*****Sigman and Lindberg 2017*****
*****Democracy for All*****
**Replication for Figures 1-9; Tables 1-4, 8-19**
**See coder-level data analysis for Tables 5-7, 11**

**Version: September 2017**

*cd "/Users/rlsigman/Dropbox/Upload/"
clear
log using "replication_main", replace
use "egal_data.dta"

*generate standardized measures (0-1) scale

*gen e_fh_status_st = (e_fh_status-1)/(3-1)
gen e_fh_cl_st = (e_fh_cl-1)/(7-1)
gen e_polity2_st = (e_polity2 +10)/(10+10)
gen v2clacjust_st = (v2clacjust + 3.019201)/(3.471141+3.019201)
gen v2clacjust_lowst = (v2clacjust_codelow + 3.892406) / (2.766015+3.892406)
gen v2clacjust_highst = (v2clacjust_codehigh + 2.280959) / (4.064263 + 2.280959)
gen v2clsocgrp_st = (v2clsocgrp + 3.147822)/( 3.331509 + 3.147822)
gen v2clsocgrp_lowst = (v2clsocgrp_codelow + 4.006242)/(2.634023+4.006242)
gen v2clsocgrp_highst = (v2clsocgrp_codehigh + 2.499701)/(3.970373 +2.499701)
gen v2peedueq_st = (v2peedueq + 3.142996)/(3.650894 + 3.142996)
gen v2peedueq_lowst = (v2peedueq_codelow + 3.800937)/ (2.844435 + 3.800937)
gen v2peedueq_highst = (v2peedueq_codehigh +2.413359)/ (4.348349 + 2.413359)
gen v2pehealth_st = (v2pehealth + 3.142996)/ (3.650894 +3.142996)
gen v2pehealth_lowst = (v2pehealth_codelow + 3.920346)/(3.2853 + 3.920346)
gen v2pehealth_highst = (v2pehealth_codehigh +2.51193)/(4.348802 + 2.51193)
gen v2pepwrsoc_st = (v2pepwrsoc + 3.006994)/(3.31124 + 3.006994)
gen v2pepwrsoc_highst = (v2pepwrsoc_codehigh + 2.319493)/(3.938705+2.319493)
gen v2pepwrsoc_lowst = (v2pepwrsoc_codelow + 3.738616)/(2.428379 + 3.738616)
gen v2pepwrgen_st = (v2pepwrgen + 2.981764)/(4.196704 +2.981764)
gen v2pepwrgen_highst = (v2pepwrgen_codehigh + 2.242911)/(4.885439+ 2.242911)
gen v2pepwrgen_lowst = (v2pepwrgen_codelow + 3.788944)/ (3.47517 + 3.788944)

*reverse freedom house 
gen e_fh_cl_st_rev = 1-e_fh_cl_st


collapse e_fh_cl_st e_fh_cl_st_rev e_polity2_st v2x_polyarchy v2clacjust_st v2clacjust_lowst v2clacjust_highst v2clsocgrp_st v2clsocgrp_highst ///
v2clsocgrp_lowst v2peedueq_st v2peedueq_lowst v2peedueq_highst v2pehealth_st v2pehealth_highst v2pehealth_lowst v2pepwrsoc_st v2pepwrsoc_highst v2pepwrsoc_lowst v2pepwrgen_st ///
v2pepwrgen_highst v2pepwrgen_lowst, by(year)

label var v2clacjust_st "Civil Liberties Across Socio-Economic Class (V-Dem)"
label var v2clsocgrp_st "Civil Liberties Across Social Groups (V-Dem)"
label var e_fh_cl_st_rev "Freedom House Civil Liberties (reverse scale)"
 label var v2pepwrgen_st "Power Distributed by Gender (V-Dem)"
 label var v2pepwrsoc_st "Power Distributed by Social Group (V-Dem)"
 label var e_polity2_st "Polity2"

*Figure 1: Freedom House, Civil Liberties equality
twoway rarea v2clacjust_highst v2clacjust_lowst year if year>1970 & year<2013, color(gs7) || ///
 rarea v2clsocgrp_highst v2clsocgrp_lowst year if year>1970 & year<2013, color(gs11)|| ///
 line v2clsocgrp_st year if year>1970 & year<2013, lcolor(black) lwidth(medium) lpattern(longdash) || ///
 line v2clacjust_st year if year>1970 & year<2013, lcolor(black) lwidth(thick) lpattern(dot)  || ///
 line e_fh_cl_st_rev year if year>1970 & year<2012, lcolor(black) lwidth(medium) legend(order(3 4 5)) ysc(r(.2 .8)) graphregion(fcolor(white))
 graph save Graph "Figure1.gph", replace
 

 ****>Additional formatting in Graph Editor
 
*Figure 2: Polity, Power distribution by social group/gender
twoway rarea v2pepwrsoc_highst v2pepwrsoc_lowst year if year>1945 & year<2013, color(gs7)|| ///
 rarea v2pepwrgen_highst v2pepwrgen_lowst year if year>1945 & year<2013, color(gs11)|| ///
 line v2pepwrsoc_st year if year>1945 & year<2013, lcolor(black) lwidth(medium) lpattern(longdash) || ///
 line v2pepwrgen_st year if year>1945 & year<2013, lcolor(black) lwidth(thick) lpattern(dot) || ///
 line e_polity2_st year if year>1945 & year<2013, lcolor(black) lwidth(medium) legend(order(3 4 5)) ysc(r(.2 .8)) graphregion(fcolor(white))
 graph save Graph "Figure2.gph", replace
 
 ****>Additional formatting in Graph Editor



 ***Table 1***

clear
use "egal_data.dta"

tabstat v2clacjust v2clsocgrp v2clsnlpct v2dlencmps v2dlunivl v2peedueq v2pehealth v2pepwrses v2pepwrsoc v2pepwrgen, stat(mean sd n) col(stat)

***Table 2***
tabstat v2xeg_eqprotec v2xeg_eqdr v2xeg_eqacc v2x_egal_small v2x_polyarchy v2x_egaldem_small, stat(mean sd min max n) col(stat)

***Table 3***
**See V-Dem Methodology and Codebook at www.v-dem.net

***Table 4***
pwcorr v2x_egaldem_small v2x_polyarchy v2x_egal_small v2xeg_eqprotec v2xeg_eqdr v2xeg_eqacc, obs sig

***Table 5***


***Table 6***

***Table 7***


***Figures 3, 4 and 5***
clear
use "egal_data.dta"

*1990-2012

drop if year< 1990 
drop if year>2012
collapse v2x_egaldem_small v2x_egal_small v2xeg_eqprotec v2xeg_eqdr v2xeg_eqacc v2x_polyarchy, by(country_text_id)
save "egal_data_collapsed.dta", replace

label var v2x_egal_small "Egalitarian Component"
label var v2x_polyarchy "Electoral Democracy (Polyarchy)"
label var v2xeg_eqprotec "Equal Protection"
label var v2xeg_eqdr "Equal Distribution"
label var v2xeg_eqacc "Equal Access"

**Figure 3**
*Egal Component and Polyarchy
graph twoway (scatter v2x_egal_small v2x_polyarchy, mlabel(country_text_id) mcolor(black) mlabcolor(black)) (lfit v2x_egal_small v2x_polyarchy, lcolor(black)), graphregion(fcolor(white)) ytitle(Egalitarian Component) legend(off)
graph save Graph "Figure3.gph", replace

**Figure 4**
*Equal Protection vs. Equal Distribution Scatter Plot 1990-2012
graph twoway (scatter v2xeg_eqdr v2xeg_eqprotec, mlabel(country_text_id) mcolor(black) mlabcolor(black)) (lfit v2xeg_eqdr v2xeg_eqprotec, lcolor(black)), graphregion(fcolor(white)) ytitle(Equal Distribution) xtitle(Equal Protection) legend(off)
graph save Graph "Figure4.gph", replace

**Figure 5**
*Equal Distribution vs. Equal Access Scatter Plot 1990-2012
graph twoway (scatter v2xeg_eqacc v2xeg_eqdr, mlabel(country_text_id) mcolor(black) mlabcolor(black)) (lfit v2xeg_eqacc v2xeg_eqdr, lcolor(black)),  graphregion(fcolor(white)) ytitle(Equal Access) xtitle(Equal Distribution) legend(off)
graph save Graph "Figure5.gph", replace



***Figures 6 and 7***
clear
use "egal_data.dta"

label var v2x_egaldem_big "Egalitarian Democracy"
label var v2x_egaldem_big_codehigh "Upper Bound"
label var v2x_egaldem_big_codehigh "Lower Bound"

**Figure 6**
graph twoway (rarea v2x_egaldem_big_codehigh v2x_egaldem_big_codelow year if country_id == 5 & year<2013, color(gs13)) || ///
 (rarea v2x_egaldem_big_codehigh v2x_egaldem_big_codelow year if country_id == 72 & year<2013, color(gs9)) || ///
 (rarea v2x_egaldem_big_codehigh v2x_egaldem_big_codelow year if country_id == 155 & year<2013, color(gs13)) || ///
 (rarea v2x_egaldem_big_codehigh v2x_egaldem_big_codelow year if country_id == 45 & year<2013, color (gs9)) || ///
 (line v2x_egaldem_big year if country_id == 5 & year<2013, lcolor(black) lpattern(dash_dot_dot)) || ///
 (line v2x_egaldem_big year if country_id == 72 & year<2013, lcolor(black) lpattern(longdash))|| ///
 (line v2x_egaldem_big year if country_id == 155 & year<2013, lcolor(black) lwidth(thick) lpattern(tight_dot)) || ///
 (line v2x_egaldem_big year if country_id == 45 & year<2013, lcolor(black) lpattern(shortdash)), legend(order(5 "Sweden" 6 "Chile" 7 "Cuba" 8 "Nigeria") region(lstyle(none))) graphregion(fcolor(white))
 graph save Graph "Figure6.gph", replace

**Additional formatting in Graph Editor

**Figure 7 US Equal Protection & Equal Distribution over time**
graph twoway (line v2xeg_eqprotec year if country_id == 20 & year < 2013, lcolor(black) lpattern(dash)) || ///
(line v2xeg_eqacc year if country_id == 20 & year < 2013, lwidth(medium) lcolor(black)) || ///
(line v2xeg_eqdr year if country_id == 20 & year < 2013, lcolor(black) lwidth(thick) lpattern(tightdot)) || ///
, graphregion(fcolor(white)) legend(order(1 "Equal Protection" 2 "Equal Access" 3 "Equal Distribution")) xlabel(1900(20)2010) 
graph save Graph "Figure7.gph", replace


***Tables 8 & 9***


**Table 8: Correlations with other V-Dem Indices**
pwcorr v2xeg_eqprotec v2xeg_eqdr v2xeg_eqacc v2x_egal_small v2x_egaldem_small v2x_polyarchy v2x_partip v2x_liberal v2xdl_delib v2x_corr v2x_cspart v2x_freexp v2x_gender v2x_suffr, obs sig

**Table 9: Correlations with Other Measures***
pwcorr v2xeg_eqprotec v2xeg_eqdr v2xeg_eqacc v2x_egal_small v2x_egaldem_small e_fh_cl e_fh_pr worker_ciri e_peedgini e_peaveduc e_peinfmor nresource_tax_inc_sc e_migdppc, obs sig

***Table 10: Correlations of Egalitarian Index and Constituent Indicators
pwcorr v2xeg_eqprotec v2xeg_eqdr v2xeg_eqacc v2x_egal_small v2x_egaldem_small v2clacjust v2clsocgrp v2clsnlpct v2dlencmps v2dlunivl v2peedueq v2pehealth v2pepwrses v2pepwrsoc v2pepwrgen, obs sig

***Figures 8 and 9***
collapse v2x_egaldem_small v2xeg_eqprotec v2xeg_eqdr v2xeg_eqacc v2x_egal_small v2x_liberal, by(year)

*Figure 8
graph twoway (line v2x_egaldem_small year if year< 2013, lwidth(medium) lcolor(black)) || ///
(line v2xeg_eqprotec year if year<2013, lcolor(black) lwidth(medium) lpattern(dash)) || ///
(line v2xeg_eqdr year if year<2013, lcolor(black) lwidth(medium) lpattern(dot)) || ///
(line v2xeg_eqacc year if year < 2013, lcolor(black) lwidth(medium) lpattern(dash_dot)), ///
xlabel(1900(20)2000) graphregion(color(white)) legend(label(1 "Egal Democracy") label(2 "Equal Protection") ///
label (3 "Equal Distribution") label(4 Equal Access))
graph save Graph "Figure8.gph", replace
*Some additional formatting in graph editor

*Figure 9
graph twoway (line v2x_egal_small year if year> 1945 & year<2013, lwidth(thick) lcolor(black)) || ///
(line v2x_liberal year if year> 1945 & year<2013, lwidth(thick) lcolor(black) lpattern(dash)), ///
ylabel(0(.2).8) xlabel(1940(15)2015) graphregion(color(white)) legend(label(1 "Egalitarian Component") label(2 "Liberal Component"))
graph save Graph "Figure9.gph", replace
*Some additional formatting in graph editor


log close
translate "replication_main.smcl" "replication_main.log", replace

